<?php


namespace api\modules\manage\controllers;


use api\modules\manage\traits\ControllerTrait;
use yii\filters\Cors;
use yii\rest\Controller;
use yii\web\Response;
use Yii;

class EasyController extends Controller
{
    use \api\traits\ControllerTrait;

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors = array_merge(['cors' => [
            'class' => Cors::className(),
        ]], $behaviors);
        if (Yii::$app->getRequest()->getMethod() !== 'OPTIONS') {
            $this->attachBehavior('checkAuth', new \api\components\behaviors\BaseBehavior());
        }
        Yii::$app->response->format = Response::FORMAT_JSON;

        return $behaviors;
    }

    public function beforeAction($action)
    {
        $method = Yii::$app->getRequest()->getMethod();
        if ($method !== 'OPTIONS') {
            // BaseBehavior.php
            if($this->check()){
                return true;
            }
        }

        return true;
    }

}